<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../inc.jsp"></jsp:include>
<meta http-equiv="X-UA-Compatible" content="edge" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>查看投票</title>
	
</head>
<script type="text/javascript">
	var finishGrid,notfinishGrid;
	$(function(){
		finishGrid = $('#finish').datagrid({
			url : '${ctx}' + '/voter/findGrid',
			queryParams:{
				"result":"1",
				"user_id":$('#user_id').val()
			},
			fit:true,
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			idField : 'id',
			sortName : 'createdatetime',
			sortOrder : 'asc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
			frozenColumns : [ [ {
				width : '100',
				title : '标题',
				field : 'title',
				sortable : true
			}, {
				width : '280',
				title : '内容',
				field : 'content',
				sortable : true
			},{
				width : '100',
				title : '开始时间',
				field : 'starttime'
			},{
				width : '100',
				title : '结束时间',
				field : 'endtime'
			}] ],
			columns : [ [ {
				width : '100',
				title : '投票类别',
				field : 'type',
				sortable : true,
				formatter : function(value, row, index) {
					switch (value) {
					case '1':
						return '一人一票';
					case'2':
						return '一人多票';
					}
				}
			},{
				width : '180',
				title : '投票时间',
				field : 'createdate',
				sortable : true
			}, {
				field : 'action',
				title : '操作',
				width : 100,
				formatter : function(value, row, index) {
					var str = '';
						str += $.formatString('<a href="javascript:void(0)" onclick="finishVoter(\'{0}\',\'{1}\');" >查看</a>', row.id,row.vi_id);
					return str;
				}
			}] ]
		});
		notfinishGrid = $('#notfinish').datagrid({
			url : '${ctx}' + '/voter/findGrid',
			queryParams:{
				"result":"3",
				"user_id":$('#user_id').val()
			},
			fit:true,
			striped : true,
			rownumbers : true,
			pagination : true,
			singleSelect : true,
			idField : 'id',
			sortName : 'createdatetime',
			sortOrder : 'asc',
			pageSize : 50,
			pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
			frozenColumns : [ [ {
				width : '100',
				title : '标题',
				field : 'title',
				sortable : true
			}, {
				width : '280',
				title : '内容',
				field : 'content',
				sortable : true
			},{
				width : '100',
				title : '开始时间',
				field : 'starttime'
			},{
				width : '100',
				title : '结束时间',
				field : 'endtime'
			}] ],
			columns : [ [ {
				width : '100',
				title : '投票类别',
				field : 'type',
				sortable : true,
				formatter : function(value, row, index) {
					switch (value) {
					case '1':
						return '一人一票';
					case '2':
						return '一人多票';
					}
				}
			},{
				width : '180',
				title : '创建时间',
				field : 'createdate',
				sortable : true
			}, {
				field : 'action',
				title : '操作',
				width : 100,
				formatter : function(value, row, index) {
					var str = '';
						str += $.formatString('<a href="javascript:void(0)" onclick="gotovoter(\'{0}\',\'{1}\');" >投票</a>', row.id,row.vi_id);
					return str;
				}
			}] ]
		});
	});
	function gotovoter(id,vi_id){
		parent.$.modalDialog({
			title : '投票',
			width : 500,
			height : 480,
			href : '${ctx}/voter/gotovoter?id='+id+'&vi_id='+vi_id,
			buttons : [ {
				text : '完成',
				handler : function() {
					var f = parent.$.modalDialog.handler.find('#userAddForm');
					var id = f.find('#id').val();
					var voters = f.find('#voters').val();
					$.ajax({
						type:'get',
						url:'${ctx}/voter/saveVoter?id='+id+'&voters='+voters,
						dataType:'json',
						success:function(data){
							alert(data.msg);
							if(data.success){
								notfinishGrid.datagrid('reload');
								finishGrid.datagrid('reload');
								parent.$.modalDialog.handler.dialog('close');
							}
						}
					});
				}
			} ]
		});
	}
	function finishVoter(id,vi_id){
		parent.$.modalDialog({
			title : '查看',
			width : 500,
			height : 480,
			href : '${ctx}/voter/finishVoter?id='+id+'&vi_id='+vi_id,
			buttons : [ {
				text : '关闭',
				handler : function() {
					parent.$.modalDialog.handler.dialog('close');
				}
			}] 
		});
	}
</script>
<body>
	<input type="hidden" id="user_id" value="${sessionInfo.id}"/>
	<div id="cc1" class="easyui-layout" data-options="fit:true">  
	    <div data-options="region:'center',title:''" style="padding:0px;background:#fff;">
	    	<div id="tt1" class="easyui-tabs" data-options="fit:true,tabPosition:'left'">   
			    <div title="已完成投票" style="padding:0px;">   
			        <table id="finish"></table>   
			    </div>   
			    <div title="未进行投票" data-options="closable:false" style="overflow:auto;padding:0px;">   
			        <table id="notfinish"></table>
			    </div>   
			</div>  
	    </div>   
	</div> 
</body>
</html>